﻿using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class Data_Passenger : Data
    {
        #region [Passenger_Insert]
        public void Passenger_Insert(Passenger data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Passenger_Insert", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Username", data.Username);
                cmd.Parameters.Add("@Password", data.Password);
                cmd.Parameters.Add("@Name", data.Name);
                cmd.Parameters.Add("@Birthday", data.Birthday);
                cmd.Parameters.Add("@Gender", data.Gender);
                cmd.Parameters.Add("@Address", data.Address);
                cmd.Parameters.Add("@Phone", data.Phone);
                cmd.Parameters.Add("@Email", data.Email);
                cmd.Parameters.Add("@Date_Of_Travel", data.Date_Of_Travel);

                cmd.ExecuteNonQuery();
            }
        }
        #endregion

        #region[Passenger_GetAll]
        public DataTable Passenger_GetAll()
        {
            using (SqlCommand cmd = new SqlCommand("sp_Passenger_GetAll", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);

                return dt;
            }
        }
        #endregion

        #region[Passenger_Update_Pass]
        public void Passenger_Update_Pass(Passenger data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Passenger_Update_Pass", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Username", data.Username);
                cmd.Parameters.Add("@Password", data.Password);

                cmd.ExecuteNonQuery();
            }
        }
        #endregion

        #region[Passenger_Update_Info]
        public void Passenger_Update_Info(Passenger data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Passenger_Update_Info", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Username", data.Username);
                cmd.Parameters.Add("@Name", data.Name);
                cmd.Parameters.Add("@Birthday", data.Birthday);
                cmd.Parameters.Add("@Gender", data.Gender);
                cmd.Parameters.Add("@Address", data.Address);
                cmd.Parameters.Add("@Phone", data.Phone);
                cmd.Parameters.Add("@Email", data.Email);
                cmd.Parameters.Add("@Date_Of_Travel", data.Date_Of_Travel);

                cmd.ExecuteNonQuery();
            }
        }
        #endregion

        #region [Passenger_CheckLogin]
        public bool Passenger_CheckLogin(string username, string pass)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Passenger_CheckLogin", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Username", username);
                cmd.Parameters.Add("@Password", pass);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                bool check = true;
                if (dt.Rows.Count > 0)
                {
                    return check = true;
                }
                else
                {
                    return check = false;
                }
            }
        }
        #endregion

        #region [Passenger_Delete]
        public void Passenger_Delete(Passenger data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Passenger_Delete", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Username",data.Username);

                cmd.ExecuteNonQuery();
            }
        }
        #endregion

        #region[Passenger_GetByName]
        public DataTable Passenger_GetByName(string username)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Passenger_GetByName", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);

                return dt;
            }
        }
        #endregion
    }
}
